package com.xixi.springboot;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@RestController
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext app)
    {
        return args -> {
            System.out.println("==================================================");
            System.out.println("由spring-boot注册的所有bean：");
            String[] beans = app.getBeanDefinitionNames();
            Arrays.sort(beans);
            for (String str: beans)
            {
                System.out.println(str);
            }
            System.out.println("==================================================\n");
        };
    }

    @RequestMapping("/user")
    public Map getUser(@RequestParam("id") String id, @RequestParam("name") String name)
    {
        Map<String, String> map = new HashMap<>();
        map.put(id, name);
        return map;
    }
}
